<!DOCTYPE HTML>
<html lang="zh-cn" class="light" dir="ltr">
    <head>
            <script type="text/x-mathjax-config">
                MathJax.Hub.Config({
                    showProcessingMessages: false,
                    messageStyle: "none",
                    extensions: ['tex2jax.js'],
                    jax: ['input/TeX', 'output/HTML-CSS'],
                    tex2jax: {
                        inlineMath: [ ['$','$'], ["\\(","\\)"] ],
                        displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
                        processEscapes: true
                    },
                    "HTML-CSS": { availableFonts: ["STIX", "TeX"] }
                });
            </script>
            
        <!-- Book generated using mdBook -->
        <meta charset="UTF-8">
        <title>类 - 仓颉编程语言扩展库 API</title>


        <!-- Custom HTML head -->
        
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="theme-color" content="#ffffff">

        <link rel="icon" href="../../../favicon.svg">
        <link rel="shortcut icon" href="../../../favicon.png">
        <link rel="stylesheet" href="../../../css/variables.css">
        <link rel="stylesheet" href="../../../css/general.css">
        <link rel="stylesheet" href="../../../css/chrome.css">
        <link rel="stylesheet" href="../../../css/print.css" media="print">

        <!-- Fonts -->
        <link rel="stylesheet" href="../../../FontAwesome/css/font-awesome.css">
        <link rel="stylesheet" href="../../../fonts/fonts.css">

        <!-- Highlight.js Stylesheets -->
        <link rel="stylesheet" href="../../../highlight.css">
        <link rel="stylesheet" href="../../../tomorrow-night.css">
        <link rel="stylesheet" href="../../../ayu-highlight.css">

        <!-- Custom theme stylesheets -->
        <link rel="stylesheet" href="../../../assets/style.css">
        <link rel="stylesheet" href="../../../assets/theme.css">

        <!-- MathJax -->
        <script async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
    </head>
    <body class="sidebar-visible no-js">
    <div id="body-container">
        <!-- Provide site root to javascript -->
        <script>
            var path_to_root = "../../../";
            var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "light" : "light";
        </script>

        <!-- Work around some values being stored in localStorage wrapped in quotes -->
        <script>
            try {
                var theme = localStorage.getItem('mdbook-theme');
                var sidebar = localStorage.getItem('mdbook-sidebar');

                if (theme.startsWith('"') && theme.endsWith('"')) {
                    localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
                }

                if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
                    localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
                }
            } catch (e) { }
        </script>

        <!-- Set the theme before any content is loaded, prevents flash -->
        <script>
            var theme;
            try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
            if (theme === null || theme === undefined) { theme = default_theme; }
            var html = document.querySelector('html');
            html.classList.remove('light')
            html.classList.add(theme);
            var body = document.querySelector('body');
            body.classList.remove('no-js')
            body.classList.add('js');
        </script>

        <input type="checkbox" id="sidebar-toggle-anchor" class="hidden">

        <!-- Hide / unhide sidebar before it is displayed -->
        <script>
            var body = document.querySelector('body');
            var sidebar = null;
            var sidebar_toggle = document.getElementById("sidebar-toggle-anchor");
            if (document.body.clientWidth >= 1080) {
                try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
                sidebar = sidebar || 'visible';
            } else {
                sidebar = 'hidden';
            }
            sidebar_toggle.checked = sidebar === 'visible';
            body.classList.remove('sidebar-visible');
            body.classList.add("sidebar-" + sidebar);
        </script>

        <nav id="sidebar" class="sidebar" aria-label="Table of contents">
            <div class="sidebar-scrollbox">
                <ol class="chapter"><li class="chapter-item expanded "><a href="../../../libs_overview.html"><strong aria-hidden="true">1.</strong> 仓颉编程语言扩展库 API</a><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../aspectCJ/aspectCJ_package_overview.html"><strong aria-hidden="true">1.1.</strong> stdx.aspectCJ</a><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../aspectCJ/aspectCJ_package_api/aspectCJ_package_classes.html"><strong aria-hidden="true">1.1.1.</strong> 类</a></li><li class="chapter-item "><div><strong aria-hidden="true">1.1.2.</strong> 示例教程</div><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../aspectCJ/aspectCJ_samples/aspectCJ_sample.html"><strong aria-hidden="true">1.1.2.1.</strong> aspecjCJ 使用</a></li></ol></li></ol></li><li class="chapter-item "><a href="../../../compress/zlib/zlib_package_overview.html"><strong aria-hidden="true">1.2.</strong> stdx.compress.zlib</a><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../compress/zlib/zlib_package_api/zlib_package_classes.html"><strong aria-hidden="true">1.2.1.</strong> 类</a></li><li class="chapter-item "><a href="../../../compress/zlib/zlib_package_api/zlib_package_enums.html"><strong aria-hidden="true">1.2.2.</strong> 枚举</a></li><li class="chapter-item "><a href="../../../compress/zlib/zlib_package_api/zlib_package_exceptions.html"><strong aria-hidden="true">1.2.3.</strong> 异常类</a></li><li class="chapter-item "><div><strong aria-hidden="true">1.2.4.</strong> 示例教程</div><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../compress/zlib/zlib_samples/deflate_compress_decompress.html"><strong aria-hidden="true">1.2.4.1.</strong> Deflate 格式数据的压缩和解压</a></li><li class="chapter-item "><a href="../../../compress/zlib/zlib_samples/gzip_compress_decompress.html"><strong aria-hidden="true">1.2.4.2.</strong> Gzip 格式数据的压缩和解压</a></li></ol></li></ol></li><li class="chapter-item "><a href="../../../crypto/crypto/crypto_package_overview.html"><strong aria-hidden="true">1.3.</strong> stdx.crypto.crypto</a><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../crypto/crypto/crypto_package_api/crypto_package_classes.html"><strong aria-hidden="true">1.3.1.</strong> 类</a></li><li class="chapter-item "><a href="../../../crypto/crypto/crypto_package_api/crypto_package_structs.html"><strong aria-hidden="true">1.3.2.</strong> 结构体</a></li><li class="chapter-item "><a href="../../../crypto/crypto/crypto_package_api/crypto_package_exceptions.html"><strong aria-hidden="true">1.3.3.</strong> 异常类</a></li><li class="chapter-item "><div><strong aria-hidden="true">1.3.4.</strong> 示例教程</div><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../crypto/crypto/crypto_samples/sample_secure_random.html"><strong aria-hidden="true">1.3.4.1.</strong> SecureRandom 使用</a></li><li class="chapter-item "><a href="../../../crypto/crypto/crypto_samples/sample_crypto.html"><strong aria-hidden="true">1.3.4.2.</strong> SM4 使用</a></li></ol></li></ol></li><li class="chapter-item "><a href="../../../crypto/digest/crypto_digest_package_overview.html"><strong aria-hidden="true">1.4.</strong> stdx.crypto.digest</a><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../crypto/digest/digest_package_api/digest_package_classes.html"><strong aria-hidden="true">1.4.1.</strong> 类</a></li><li class="chapter-item "><a href="../../../crypto/digest/digest_package_api/digest_package_structs.html"><strong aria-hidden="true">1.4.2.</strong> 结构体</a></li><li class="chapter-item "><a href="../../../crypto/digest/digest_package_api/digest_package_exceptions.html"><strong aria-hidden="true">1.4.3.</strong> 异常类</a></li><li class="chapter-item "><div><strong aria-hidden="true">1.4.4.</strong> 示例教程</div><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../crypto/digest/digest_samples/sample_digest.html"><strong aria-hidden="true">1.4.4.1.</strong> digest 使用</a></li></ol></li></ol></li><li class="chapter-item "><a href="../../../crypto/keys/keys_package_overview.html"><strong aria-hidden="true">1.5.</strong> stdx.crypto.keys</a><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../crypto/keys/keys_package_api/keys_package_classes.html"><strong aria-hidden="true">1.5.1.</strong> 类</a></li><li class="chapter-item "><a href="../../../crypto/keys/keys_package_api/keys_package_enums.html"><strong aria-hidden="true">1.5.2.</strong> 枚举</a></li><li class="chapter-item "><a href="../../../crypto/keys/keys_package_api/keys_package_structs.html"><strong aria-hidden="true">1.5.3.</strong> 结构体</a></li><li class="chapter-item "><div><strong aria-hidden="true">1.5.4.</strong> 示例教程</div><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../crypto/keys/keys_samples/sample_keys.html"><strong aria-hidden="true">1.5.4.1.</strong> keys 使用</a></li></ol></li></ol></li><li class="chapter-item "><a href="../../../crypto/x509/x509_package_overview.html"><strong aria-hidden="true">1.6.</strong> stdx.crypto.x509</a><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../crypto/x509/x509_package_api/x509_package_type.html"><strong aria-hidden="true">1.6.1.</strong> 类型别名</a></li><li class="chapter-item "><a href="../../../crypto/x509/x509_package_api/x509_package_interfaces.html"><strong aria-hidden="true">1.6.2.</strong> 接口</a></li><li class="chapter-item "><a href="../../../crypto/x509/x509_package_api/x509_package_classes.html"><strong aria-hidden="true">1.6.3.</strong> 类</a></li><li class="chapter-item "><a href="../../../crypto/x509/x509_package_api/x509_package_enums.html"><strong aria-hidden="true">1.6.4.</strong> 枚举</a></li><li class="chapter-item "><a href="../../../crypto/x509/x509_package_api/x509_package_structs.html"><strong aria-hidden="true">1.6.5.</strong> 结构体</a></li><li class="chapter-item "><a href="../../../crypto/x509/x509_package_api/x509_package_exceptions.html"><strong aria-hidden="true">1.6.6.</strong> 异常类</a></li><li class="chapter-item "><div><strong aria-hidden="true">1.6.7.</strong> 示例教程</div><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../crypto/x509/x509_samples/sample_x509.html"><strong aria-hidden="true">1.6.7.1.</strong> x509 使用</a></li></ol></li></ol></li><li class="chapter-item "><a href="../../../encoding/base64/base64_package_overview.html"><strong aria-hidden="true">1.7.</strong> stdx.encoding.base64</a><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../encoding/base64/base64_package_api/base64_package_funcs.html"><strong aria-hidden="true">1.7.1.</strong> 函数</a></li><li class="chapter-item "><div><strong aria-hidden="true">1.7.2.</strong> 示例教程</div><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../encoding/base64/base64_samples/base64.html"><strong aria-hidden="true">1.7.2.1.</strong> Byte 数组和 Base64 互转</a></li></ol></li></ol></li><li class="chapter-item "><a href="../../../encoding/hex/hex_package_overview.html"><strong aria-hidden="true">1.8.</strong> stdx.encoding.hex</a><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../encoding/hex/hex_package_api/hex_package_funcs.html"><strong aria-hidden="true">1.8.1.</strong> 函数</a></li><li class="chapter-item "><div><strong aria-hidden="true">1.8.2.</strong> 示例教程</div><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../encoding/hex/hex_samples/hex.html"><strong aria-hidden="true">1.8.2.1.</strong> Byte 数组和 Hex 互转</a></li></ol></li></ol></li><li class="chapter-item "><a href="../../../encoding/json/json_package_overview.html"><strong aria-hidden="true">1.9.</strong> stdx.encoding.json</a><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../encoding/json/json_package_api/encoding_json_package_interfaces.html"><strong aria-hidden="true">1.9.1.</strong> 接口</a></li><li class="chapter-item "><a href="../../../encoding/json/json_package_api/encoding_json_package_classes.html"><strong aria-hidden="true">1.9.2.</strong> 类</a></li><li class="chapter-item "><a href="../../../encoding/json/json_package_api/encoding_json_package_enums.html"><strong aria-hidden="true">1.9.3.</strong> 枚举</a></li><li class="chapter-item "><a href="../../../encoding/json/json_package_api/encoding_json_package_exceptions.html"><strong aria-hidden="true">1.9.4.</strong> 异常类</a></li><li class="chapter-item "><div><strong aria-hidden="true">1.9.5.</strong> 示例教程</div><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../encoding/json/json_samples/json_array_sample.html"><strong aria-hidden="true">1.9.5.1.</strong> JsonArray 使用示例</a></li><li class="chapter-item "><a href="../../../encoding/json/json_samples/json_value_sample.html"><strong aria-hidden="true">1.9.5.2.</strong> JsonValue 和 String 互相转换</a></li><li class="chapter-item "><a href="../../../encoding/json/json_samples/to_json_sample.html"><strong aria-hidden="true">1.9.5.3.</strong> JsonValue 与 DataModel 的转换</a></li></ol></li></ol></li><li class="chapter-item "><a href="../../../encoding/json_stream/json_stream_package_overview.html"><strong aria-hidden="true">1.10.</strong> stdx.encoding.json.stream</a><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../encoding/json_stream/json_stream_package_api/encoding_json_stream_package_interfaces.html"><strong aria-hidden="true">1.10.1.</strong> 接口</a></li><li class="chapter-item "><a href="../../../encoding/json_stream/json_stream_package_api/encoding_json_stream_package_classes.html"><strong aria-hidden="true">1.10.2.</strong> 类</a></li><li class="chapter-item "><a href="../../../encoding/json_stream/json_stream_package_api/encoding_json_stream_package_enums.html"><strong aria-hidden="true">1.10.3.</strong> 枚举</a></li><li class="chapter-item "><a href="../../../encoding/json_stream/json_stream_package_api/encoding_json_stream_package_structs.html"><strong aria-hidden="true">1.10.4.</strong> 结构体</a></li><li class="chapter-item "><div><strong aria-hidden="true">1.10.5.</strong> 示例教程</div><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../encoding/json_stream/json_stream_samples/sample_json_reader.html"><strong aria-hidden="true">1.10.5.1.</strong> 使用 Json Stream 进行反序列化</a></li><li class="chapter-item "><a href="../../../encoding/json_stream/json_stream_samples/sample_json_writer.html"><strong aria-hidden="true">1.10.5.2.</strong> 使用 Json Stream 进行序列化</a></li><li class="chapter-item "><a href="../../../encoding/json_stream/json_stream_samples/sample_json_writeconfig.html"><strong aria-hidden="true">1.10.5.3.</strong> WriteConfig 使用示例</a></li></ol></li></ol></li><li class="chapter-item expanded "><a href="../../../encoding/url/url_package_overview.html"><strong aria-hidden="true">1.11.</strong> stdx.encoding.url</a><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item expanded "><a href="../../../encoding/url/url_package_api/url_package_classes.html" class="active"><strong aria-hidden="true">1.11.1.</strong> 类</a></li><li class="chapter-item "><a href="../../../encoding/url/url_package_api/url_package_exceptions.html"><strong aria-hidden="true">1.11.2.</strong> 异常类</a></li><li class="chapter-item "><div><strong aria-hidden="true">1.11.3.</strong> 示例教程</div><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../encoding/url/url_samples/form.html"><strong aria-hidden="true">1.11.3.1.</strong> Form 的构造使用</a></li><li class="chapter-item "><a href="../../../encoding/url/url_samples/url_parse.html"><strong aria-hidden="true">1.11.3.2.</strong> URL 解析函数 parse 的使用</a></li></ol></li></ol></li><li class="chapter-item "><a href="../../../fuzz/fuzz_package_overview.html"><strong aria-hidden="true">1.12.</strong> stdx.fuzz.fuzz</a><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../fuzz/fuzz_package_api/fuzz_package_constants_vars.html"><strong aria-hidden="true">1.12.1.</strong> 常量变量</a></li><li class="chapter-item "><a href="../../../fuzz/fuzz_package_api/fuzz_package_classes.html"><strong aria-hidden="true">1.12.2.</strong> 类</a></li><li class="chapter-item "><a href="../../../fuzz/fuzz_package_api/fuzz_package_exceptions.html"><strong aria-hidden="true">1.12.3.</strong> 异常类</a></li><li class="chapter-item "><div><strong aria-hidden="true">1.12.4.</strong> 示例教程</div><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../fuzz/fuzz_samples/basic_fuzzing_test.html"><strong aria-hidden="true">1.12.4.1.</strong> 测试猜测字符功能</a></li><li class="chapter-item "><a href="../../../fuzz/fuzz_samples/dataprovider_usage.html"><strong aria-hidden="true">1.12.4.2.</strong> 使用 DataProvider 功能进行测试</a></li><li class="chapter-item "><a href="../../../fuzz/fuzz_samples/fake_coverage_usage.html"><strong aria-hidden="true">1.12.4.3.</strong> 使用 FakeCoverage 避免 DataProvider 模式下 Fuzz 异常终止</a></li><li class="chapter-item "><a href="../../../fuzz/fuzz_samples/print_cj-fuzz_usage.html"><strong aria-hidden="true">1.12.4.4.</strong> 打印 fuzz 使用方法</a></li><li class="chapter-item "><a href="../../../fuzz/fuzz_samples/print_coverage.html"><strong aria-hidden="true">1.12.4.5.</strong> 实验性特性-覆盖率信息打印</a></li><li class="chapter-item "><a href="../../../fuzz/fuzz_samples/stack_backtrace_missing_solution.html"><strong aria-hidden="true">1.12.4.6.</strong> 栈回溯缺失的处理方案</a></li></ol></li></ol></li><li class="chapter-item "><a href="../../../log/log_package_overview.html"><strong aria-hidden="true">1.13.</strong> stdx.log</a><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../log/log_package_api/log_package_types.html"><strong aria-hidden="true">1.13.1.</strong> 类型别名</a></li><li class="chapter-item "><a href="../../../log/log_package_api/log_package_funcs.html"><strong aria-hidden="true">1.13.2.</strong> 函数</a></li><li class="chapter-item "><a href="../../../log/log_package_api/log_package_interfaces.html"><strong aria-hidden="true">1.13.3.</strong> 接口</a></li><li class="chapter-item "><a href="../../../log/log_package_api/log_package_classes.html"><strong aria-hidden="true">1.13.4.</strong> 类</a></li><li class="chapter-item "><a href="../../../log/log_package_api/log_package_structs.html"><strong aria-hidden="true">1.13.5.</strong> 结构体</a></li><li class="chapter-item "><a href="../../../log/log_package_api/log_package_exceptions.html"><strong aria-hidden="true">1.13.6.</strong> 异常类</a></li><li class="chapter-item "><div><strong aria-hidden="true">1.13.7.</strong> 示例教程</div><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../log/log_samples/log_sample.html"><strong aria-hidden="true">1.13.7.1.</strong> 日志打印示例</a></li></ol></li></ol></li><li class="chapter-item "><a href="../../../logger/logger_package_overview.html"><strong aria-hidden="true">1.14.</strong> stdx.logger</a><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../logger/logger_package_api/logger_package_classes.html"><strong aria-hidden="true">1.14.1.</strong> 类</a></li><li class="chapter-item "><div><strong aria-hidden="true">1.14.2.</strong> 示例教程</div><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../logger/logger_samples/logger_sample.html"><strong aria-hidden="true">1.14.2.1.</strong> 日志打印示例</a></li></ol></li></ol></li><li class="chapter-item "><a href="../../../net/http/http_package_overview.html"><strong aria-hidden="true">1.15.</strong> stdx.net.http</a><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../net/http/http_package_api/http_package_funcs.html"><strong aria-hidden="true">1.15.1.</strong> 函数</a></li><li class="chapter-item "><a href="../../../net/http/http_package_api/http_package_interfaces.html"><strong aria-hidden="true">1.15.2.</strong> 接口</a></li><li class="chapter-item "><a href="../../../net/http/http_package_api/http_package_classes.html"><strong aria-hidden="true">1.15.3.</strong> 类</a></li><li class="chapter-item "><a href="../../../net/http/http_package_api/http_package_enums.html"><strong aria-hidden="true">1.15.4.</strong> 枚举</a></li><li class="chapter-item "><a href="../../../net/http/http_package_api/http_package_structs.html"><strong aria-hidden="true">1.15.5.</strong> 结构体</a></li><li class="chapter-item "><a href="../../../net/http/http_package_api/http_package_exceptions.html"><strong aria-hidden="true">1.15.6.</strong> 异常类</a></li><li class="chapter-item "><div><strong aria-hidden="true">1.15.7.</strong> 示例教程</div><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../net/http/http_samples/http_client.html"><strong aria-hidden="true">1.15.7.1.</strong> client</a></li><li class="chapter-item "><a href="../../../net/http/http_samples/cookie.html"><strong aria-hidden="true">1.15.7.2.</strong> cookie</a></li><li class="chapter-item "><a href="../../../net/http/http_samples/log.html"><strong aria-hidden="true">1.15.7.3.</strong> log</a></li><li class="chapter-item "><a href="../../../net/http/http_samples/http_server.html"><strong aria-hidden="true">1.15.7.4.</strong> server</a></li><li class="chapter-item "><a href="../../../net/http/http_samples/webSocket.html"><strong aria-hidden="true">1.15.7.5.</strong> webSocket</a></li></ol></li></ol></li><li class="chapter-item "><a href="../../../net/tls/tls_package_overview.html"><strong aria-hidden="true">1.16.</strong> stdx.net.tls</a><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../net/tls/tls_package_api/tls_package_classes.html"><strong aria-hidden="true">1.16.1.</strong> 类</a></li><li class="chapter-item "><a href="../../../net/tls/tls_package_api/tls_package_enums.html"><strong aria-hidden="true">1.16.2.</strong> 枚举</a></li><li class="chapter-item "><a href="../../../net/tls/tls_package_api/tls_package_structs.html"><strong aria-hidden="true">1.16.3.</strong> 结构体</a></li><li class="chapter-item "><a href="../../../net/tls/tls_package_api/tls_package_exceptions.html"><strong aria-hidden="true">1.16.4.</strong> 异常类</a></li><li class="chapter-item "><div><strong aria-hidden="true">1.16.5.</strong> 示例教程</div><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../net/tls/tls_samples/cert_key.html"><strong aria-hidden="true">1.16.5.1.</strong> 服务端证书及公钥在一份文件中</a></li><li class="chapter-item "><a href="../../../net/tls/tls_samples/client.html"><strong aria-hidden="true">1.16.5.2.</strong> 客户端示例</a></li><li class="chapter-item "><a href="../../../net/tls/tls_samples/hot_update_cert.html"><strong aria-hidden="true">1.16.5.3.</strong> 证书热更新</a></li><li class="chapter-item "><a href="../../../net/tls/tls_samples/server.html"><strong aria-hidden="true">1.16.5.4.</strong> 服务端示例</a></li></ol></li></ol></li><li class="chapter-item "><a href="../../../serialization/serialization_package_overview.html"><strong aria-hidden="true">1.17.</strong> stdx.serialization.serialization</a><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../serialization/serialization_package_api/serialization_package_functions.html"><strong aria-hidden="true">1.17.1.</strong> 函数</a></li><li class="chapter-item "><a href="../../../serialization/serialization_package_api/serialization_package_interfaces.html"><strong aria-hidden="true">1.17.2.</strong> 接口</a></li><li class="chapter-item "><a href="../../../serialization/serialization_package_api/serialization_package_classes.html"><strong aria-hidden="true">1.17.3.</strong> 类</a></li><li class="chapter-item "><a href="../../../serialization/serialization_package_api/serialization_package_exceptions.html"><strong aria-hidden="true">1.17.4.</strong> 异常类</a></li><li class="chapter-item "><div><strong aria-hidden="true">1.17.5.</strong> 示例教程</div><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../serialization/serialization_samples/serialize_and_deserialize_class.html"><strong aria-hidden="true">1.17.5.1.</strong> class 序列化和反序列化</a></li><li class="chapter-item "><a href="../../../serialization/serialization_samples/serialize_hashmap_and_hashset.html"><strong aria-hidden="true">1.17.5.2.</strong> HashSet 和 HashMap 序列化</a></li></ol></li></ol></li><li class="chapter-item "><a href="../../../unittest/data/data_package_overview.html"><strong aria-hidden="true">1.18.</strong> stdx.unittest.data</a><a class="toggle"><div>❱</div></a></li><li><ol class="section"><li class="chapter-item "><a href="../../../unittest/data/data_package_api/data_package_functions.html"><strong aria-hidden="true">1.18.1.</strong> 函数</a></li><li class="chapter-item "><a href="../../../unittest/data/data_package_api/data_package_classes.html"><strong aria-hidden="true">1.18.2.</strong> 类</a></li></ol></li></ol></li></ol>
            </div>
            <div id="sidebar-resize-handle" class="sidebar-resize-handle">
                <div class="sidebar-resize-indicator"></div>
            </div>
        </nav>

        <!-- Track and set sidebar scroll position -->
        <script>
            var sidebarScrollbox = document.querySelector('#sidebar .sidebar-scrollbox');
            sidebarScrollbox.addEventListener('click', function(e) {
                if (e.target.tagName === 'A') {
                    sessionStorage.setItem('sidebar-scroll', sidebarScrollbox.scrollTop);
                }
            }, { passive: true });
            var sidebarScrollTop = sessionStorage.getItem('sidebar-scroll');
            sessionStorage.removeItem('sidebar-scroll');
            if (sidebarScrollTop) {
                // preserve sidebar scroll position when navigating via links within sidebar
                sidebarScrollbox.scrollTop = sidebarScrollTop;
            } else {
                // scroll sidebar to current active section when navigating via "next/previous chapter" buttons
                var activeSection = document.querySelector('#sidebar .active');
                if (activeSection) {
                    activeSection.scrollIntoView({ block: 'center' });
                }
            }
        </script>

        <div id="page-wrapper" class="page-wrapper">

            <div class="page">
                                <div id="menu-bar-hover-placeholder"></div>
                <div id="menu-bar" class="menu-bar sticky">
                    <div class="left-buttons">
                        <label id="sidebar-toggle" class="icon-button" for="sidebar-toggle-anchor" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
                            <i class="fa fa-bars"></i>
                        </label>
                        <button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
                            <i class="fa fa-paint-brush"></i>
                        </button>
                        <ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
                            <li role="none"><button role="menuitem" class="theme" id="light">Light</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
                        </ul>
                        <button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
                            <i class="fa fa-search"></i>
                        </button>
                    </div>

                    <h1 class="menu-title">仓颉编程语言扩展库 API</h1>

                    <div class="right-buttons">
                        <a href="../../../print.html" title="Print this book" aria-label="Print this book">
                            <i id="print-button" class="fa fa-print"></i>
                        </a>

                    </div>
                </div>

                <div id="search-wrapper" class="hidden">
                    <form id="searchbar-outer" class="searchbar-outer">
                        <input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
                    </form>
                    <div id="searchresults-outer" class="searchresults-outer hidden">
                        <div id="searchresults-header" class="searchresults-header"></div>
                        <ul id="searchresults">
                        </ul>
                    </div>
                </div>

                <!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
                <script>
                    document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
                    document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
                    Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
                        link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
                    });
                </script>

                <div id="content" class="content">
                    <main>
                        <h1 id="类"><a class="header" href="#类">类</a></h1>
<h2 id="class-form"><a class="header" href="#class-form">class Form</a></h2>
<pre><code class="language-cangjie">public class Form {
    public init()
    public init(queryComponent: String)
}
</code></pre>
<p>功能：<a href="url_package_classes.html#class-form">Form</a> 以 key-value 键值对形式存储 http 请求的表单信息，通常为请求 <a href="url_package_classes.html#class-url">URL</a> 中的 query 部分。</p>
<p>同一个 key 可以对应多个 value，value 以数组形式存储。<code>&amp;</code> 符号分隔多个键值对；<code>=</code> 分隔的左侧作为 key 值，右侧作为 value 值（没有 <code>=</code> 或者 value 为空，均是允许的）。使用示例见 <a href="../url_samples/form.html#Form-%E7%9A%84%E6%9E%84%E9%80%A0%E4%BD%BF%E7%94%A8">Form 的构造使用</a>。</p>
<h3 id="init"><a class="header" href="#init">init()</a></h3>
<pre><code class="language-cangjie">public init()
</code></pre>
<p>功能：构造一个默认的 <a href="url_package_classes.html#class-form">Form</a> 实例。</p>
<h3 id="initstring"><a class="header" href="#initstring">init(String)</a></h3>
<pre><code class="language-cangjie">public init(queryComponent: String)
</code></pre>
<p>功能：根据 <a href="url_package_classes.html#class-url">URL</a> 编码的查询字符串，即 <a href="url_package_classes.html#class-url">URL</a> 实例的 query 部分构造 <a href="url_package_classes.html#class-form">Form</a> 实例。</p>
<p>解析 <a href="url_package_classes.html#class-url">URL</a> 编码的查询字符串，得到若干键值对，并将其添加到新构造的 <a href="url_package_classes.html#class-form">Form</a> 实例中。</p>
<p>参数：</p>
<ul>
<li>queryComponent: String - <a href="url_package_classes.html#class-url">URL</a> 的 query 组件部分的字符串，但是不包括组件前面的 <code>?</code> 符号。</li>
</ul>
<p>异常：</p>
<ul>
<li>IllegalArgumentException - 当<a href="url_package_classes.html#class-url">URL</a> 字符串中包含不符合 utf8 编码规则的字节时，抛出异常。</li>
<li><a href="url_package_exceptions.html#class-urlsyntaxexception">UrlSyntaxException</a> - 当 <a href="url_package_classes.html#class-url">URL</a> 字符串中包含非法转义字符时，抛出异常。</li>
</ul>
<h3 id="func-addstring-string"><a class="header" href="#func-addstring-string">func add(String, String)</a></h3>
<pre><code class="language-cangjie">public func add(key: String, value: String): Unit
</code></pre>
<p>功能：新增 key-value 映射，如果 key 已存在，则将 value 添加到原来 value 数组的最后面。</p>
<p>参数：</p>
<ul>
<li>key: String - 指定键，可以是新增的。</li>
<li>value: String - 将该值添加到指定键对应的值数组中。</li>
</ul>
<h3 id="func-clone"><a class="header" href="#func-clone">func clone()</a></h3>
<pre><code class="language-cangjie">public func clone(): Form
</code></pre>
<p>功能：克隆 <a href="url_package_classes.html#class-form">Form</a>。</p>
<p>返回值：</p>
<ul>
<li><a href="url_package_classes.html#class-form">Form</a> - 克隆得到的新 <a href="url_package_classes.html#class-form">Form</a> 实例。</li>
</ul>
<h3 id="func-getstring"><a class="header" href="#func-getstring">func get(String)</a></h3>
<pre><code class="language-cangjie">public func get(key: String): Option&lt;String&gt;
</code></pre>
<p>功能：根据 key 获取第一个对应的 value 值。</p>
<p>举例：</p>
<ul>
<li>当 query 组件部分是 <code>a=b</code> 时，<code>form.get(&quot;a&quot;)</code>获得 <code>Some(b)</code>。</li>
<li>当 query 组件部分是 <code>a=</code> 时，<code>form.get(&quot;a&quot;)</code>获得 <code>Some()</code>。</li>
<li>当 query 组件部分是 <code>a</code> 时，<code>form.get(&quot;a&quot;)</code>获得 <code>Some()</code>。</li>
<li>当 query 组件部分是 <code>a</code> 时，<code>form.get(&quot;c&quot;)</code>获得 <code>None</code>。</li>
</ul>
<p>参数：</p>
<ul>
<li>key: String - 指定键。</li>
</ul>
<p>返回值：</p>
<ul>
<li>Option&lt;String&gt; - 根据指定键获取的第一个值，用 Option&lt;String&gt; 类型表示。</li>
</ul>
<h3 id="func-getallstring"><a class="header" href="#func-getallstring">func getAll(String)</a></h3>
<pre><code class="language-cangjie">public func getAll(key: String): ArrayList&lt;String&gt;
</code></pre>
<p>功能：根据指定的键（key）获取该键（key）对应的所有 value 值。</p>
<p>参数：</p>
<ul>
<li>key: String - 用户指定的键（key），用于获取对应的 value 值。</li>
</ul>
<p>返回值：</p>
<ul>
<li>ArrayList&lt;String&gt; - 根据指定键（key）获取的全部 value 值对应的数组。当指定键（key）不存在时，返回空数组。</li>
</ul>
<h3 id="func-isempty"><a class="header" href="#func-isempty">func isEmpty()</a></h3>
<pre><code class="language-cangjie">public func isEmpty(): Bool
</code></pre>
<p>功能：判断 <a href="url_package_classes.html#class-form">Form</a> 是否为空。</p>
<p>返回值：</p>
<ul>
<li>Bool - 如果为空，则返回 true；否则，返回 false。</li>
</ul>
<h3 id="func-removestring"><a class="header" href="#func-removestring">func remove(String)</a></h3>
<pre><code class="language-cangjie">public func remove(key: String): Unit
</code></pre>
<p>功能：删除 key 及其对应 value。</p>
<p>参数：</p>
<ul>
<li>key: String - 需要删除的键。</li>
</ul>
<h3 id="func-setstring-string"><a class="header" href="#func-setstring-string">func set(String, String)</a></h3>
<pre><code class="language-cangjie">public func set(key: String, value: String): Unit
</code></pre>
<p>功能：重置指定 key 对应的 value。</p>
<p>参数：</p>
<ul>
<li>key: String - 指定键。</li>
<li>value: String - 将指定键的值设置为 value。</li>
</ul>
<h3 id="func-toencodestring"><a class="header" href="#func-toencodestring">func toEncodeString()</a></h3>
<pre><code class="language-cangjie">public func toEncodeString(): String
</code></pre>
<p>功能：对表单中的键值对进行编码，编码采用百分号编码。</p>
<p>未保留字符不会被编码，空格将编码为 '+'。</p>
<blockquote>
<p><strong>说明：</strong></p>
<p>RFC 3986 协议中对未保留字符定义如下： unreserved = ALPHA / DIGIT / &quot;-&quot; / &quot;.&quot; / &quot;_&quot; / &quot;~&quot;</p>
</blockquote>
<p>返回值：</p>
<ul>
<li>String - 编码后的字符串。</li>
</ul>
<h2 id="class-url"><a class="header" href="#class-url">class URL</a></h2>
<pre><code class="language-cangjie">public class URL &lt;: ToString {
    public init(scheme!: String, hostName!: String, path!: String)
}
</code></pre>
<p>功能：该类提供解析 <a href="url_package_classes.html#class-url">URL</a> 的函数以及其他相关函数。</p>
<p>字符串中被百分号<code>%</code>编码的内容会被解码，保存在相应的组件之中，而初始值保存在相应的 <code>raw</code> 属性之中。<a href="url_package_classes.html#class-url">URL</a> 中的用户名和密码部分（如果存在的话）也会按照 RFC 3986 协议的说明被解析。</p>
<blockquote>
<p><strong>注意：</strong></p>
<p>RFC 3986 明确说明在任何场景下，明文保存用户信息存在被泄露风险，所以建议不要在 URL 中明文保存用户信息。</p>
</blockquote>
<p>父类型：</p>
<ul>
<li>ToString</li>
</ul>
<h3 id="prop-fragment"><a class="header" href="#prop-fragment">prop fragment</a></h3>
<pre><code class="language-cangjie">public prop fragment: ?String
</code></pre>
<p>功能：获取解码后的锚点组件，用字符串表示。</p>
<p>类型：?String</p>
<h3 id="prop-host"><a class="header" href="#prop-host">prop host</a></h3>
<pre><code class="language-cangjie">public prop host: String
</code></pre>
<p>功能：获取解码后的主机名和端口部分，用字符串表示。</p>
<p>类型：String</p>
<h3 id="prop-hostname"><a class="header" href="#prop-hostname">prop hostName</a></h3>
<pre><code class="language-cangjie">public prop hostName: String
</code></pre>
<p>功能：获取解码后的主机名，用字符串表示。</p>
<p>类型：String</p>
<h3 id="prop-opaque"><a class="header" href="#prop-opaque">prop opaque</a></h3>
<pre><code class="language-cangjie">public prop opaque: String
</code></pre>
<p>功能：获取 <a href="url_package_classes.html#class-url">URL</a> 中未被解析的部分，用字符串表示。</p>
<p>类型：String</p>
<p>示例：</p>
<pre><code class="language-cangjie">import stdx.encoding.url.*

main () {
    let url = URL.parse(&quot;https:\\\\/example.com/foo/bar&quot;) // '\' 不是协议规定的分割符，无法被解析。
    println(&quot;url.scheme=${url.scheme}&quot;)
    println(&quot;url.host=${url.host}&quot;)
    println(&quot;url.opaque=${url.opaque}&quot;)
}
</code></pre>
<p>运行结果：</p>
<pre><code class="language-text">url.scheme=https
url.host=
url.opaque=\\/example.com/foo/bar
</code></pre>
<h3 id="prop-path"><a class="header" href="#prop-path">prop path</a></h3>
<pre><code class="language-cangjie">public prop path: String
</code></pre>
<p>功能：获取解码后的路径，用字符串表示。</p>
<p>类型：String</p>
<h3 id="prop-port"><a class="header" href="#prop-port">prop port</a></h3>
<pre><code class="language-cangjie">public prop port: String
</code></pre>
<p>功能：获取端口号，用字符串表示，空字符串表示无端口号。</p>
<p>类型：String</p>
<h3 id="prop-query"><a class="header" href="#prop-query">prop query</a></h3>
<pre><code class="language-cangjie">public prop query: ?String
</code></pre>
<p>功能：获取解码后的查询组件，用字符串表示。</p>
<p>类型：?String</p>
<h3 id="prop-queryform"><a class="header" href="#prop-queryform">prop queryForm</a></h3>
<pre><code class="language-cangjie">public prop queryForm: Form
</code></pre>
<p>功能：获取解码后的查询组件，用 <a href="url_package_classes.html#class-form">Form</a> 实例表示。</p>
<p>类型：<a href="url_package_classes.html#class-form">Form</a></p>
<h3 id="prop-rawfragment"><a class="header" href="#prop-rawfragment">prop rawFragment</a></h3>
<pre><code class="language-cangjie">public prop rawFragment: ?String
</code></pre>
<p>功能：获取解码前的锚点组件，用字符串表示。</p>
<p>类型：?String</p>
<h3 id="prop-rawpath"><a class="header" href="#prop-rawpath">prop rawPath</a></h3>
<pre><code class="language-cangjie">public prop rawPath: String
</code></pre>
<p>功能：获取解码前的路径，用字符串表示。</p>
<p>类型：String</p>
<h3 id="prop-rawquery"><a class="header" href="#prop-rawquery">prop rawQuery</a></h3>
<pre><code class="language-cangjie">public prop rawQuery: ?String
</code></pre>
<p>功能：获取解码前的查询组件，用字符串表示。</p>
<p>类型：?String</p>
<h3 id="prop-rawuserinfo"><a class="header" href="#prop-rawuserinfo">prop rawUserInfo</a></h3>
<pre><code class="language-cangjie">public prop rawUserInfo: UserInfo
</code></pre>
<p>功能：获取解码前的用户名和密码信息，用 <a href="url_package_classes.html#class-userinfo">UserInfo</a> 实例表示。</p>
<p>类型：<a href="url_package_classes.html#class-userinfo">UserInfo</a></p>
<h3 id="prop-scheme"><a class="header" href="#prop-scheme">prop scheme</a></h3>
<pre><code class="language-cangjie">public prop scheme: String
</code></pre>
<p>功能：获取 <a href="url_package_classes.html#class-url">URL</a> 中协议部分，用字符串表示。</p>
<p>类型：String</p>
<h3 id="prop-userinfo"><a class="header" href="#prop-userinfo">prop userInfo</a></h3>
<pre><code class="language-cangjie">public prop userInfo: UserInfo
</code></pre>
<p>功能：获取解码后的用户名和密码信息，用 <a href="url_package_classes.html#class-userinfo">UserInfo</a> 实例表示。</p>
<p>类型：<a href="url_package_classes.html#class-userinfo">UserInfo</a></p>
<h3 id="initstring-string-string"><a class="header" href="#initstring-string-string">init(String, String, String)</a></h3>
<pre><code class="language-cangjie">public init(scheme!: String, hostName!: String, path!: String)
</code></pre>
<p>功能：构造一个 <a href="url_package_classes.html#class-url">URL</a> 实例。</p>
<p>构造实例时需要满足要求：</p>
<ul>
<li>拥有主机名 hostName 时，需要有协议 scheme。</li>
<li>不能只存在协议 scheme。</li>
<li>存在协议和路径的情况下，路径 path 必须是绝对路径。</li>
</ul>
<p>参数：</p>
<ul>
<li>scheme!: String - 协议类型。</li>
<li>hostName!: String - 不包含端口号的主机名。</li>
<li>path!: String - 请求资源的路径。</li>
</ul>
<p>异常：</p>
<ul>
<li><a href="url_package_exceptions.html#class-urlsyntaxexception">UrlSyntaxException</a> - 当构造实例不满足要求时，抛出异常。</li>
</ul>
<h3 id="static-func-mergepathsstring-string"><a class="header" href="#static-func-mergepathsstring-string">static func mergePaths(String, String)</a></h3>
<pre><code class="language-cangjie">public static func mergePaths(basePath: String, refPath: String): String
</code></pre>
<p>功能：合并两个路径。</p>
<p>合并规则：将引用路径 refPath 追加到基础路径 basePath 的最后一段。如果 refPath 是绝对路径，结果就是 refPath 原本的值。如果 refPath 不是绝对路径，则将自身拼接至 basePath 最后一个 <code>/</code> 后，所有结果最终都会进行标准化（路径中的<code>.</code>字符，<code>..</code>字符，以及多个连续的 <code>/</code> 字符都会被优化）。具体行为可以参照下面示例。更详细行为参考 RFC 3986 协议。</p>
<p>如需合并 URL 请使用 <a href="#func-resolveurlurl">resolveURL</a>。</p>
<p>例如：</p>
<ul>
<li><code>/a/b/c</code> 合并 <code>/d</code> 输出 <code>/d</code>。</li>
<li><code>/a/b/c</code> 合并 <code>d</code> 输出 <code>/a/b/d</code>。</li>
<li><code>/a/b/</code> 合并 <code>d/e/../f</code> 输出 <code>/a/b/d/f</code>。</li>
<li><code>/a/b/c/</code> 合并 <code>./../../g</code> 输出 <code>/a/g</code>。</li>
</ul>
<p>参数：</p>
<ul>
<li>basePath: String - 基础路径。</li>
<li>refPath: String - 引用路径。</li>
</ul>
<p>返回值：</p>
<ul>
<li>String - 合并且标准化后的路径。</li>
</ul>
<h3 id="static-func-parsestring"><a class="header" href="#static-func-parsestring">static func parse(String)</a></h3>
<pre><code class="language-cangjie">public static func parse(rawUrl: String): URL
</code></pre>
<p>功能：将原始 URL 字符串解析成 <a href="url_package_classes.html#class-url">URL</a> 对象。</p>
<p>这个函数会将 <a href="url_package_classes.html#class-url">URL</a> 按照组件分解，然后分别进行解码并存储在相应的组件属性中，而 rawXXX (此处泛指前缀是 raw 的 URL 属性)属性部分存储的是原始值，不做编解码处理。</p>
<p>使用示例请参见<a href="./../url_samples/url_parse.html#url-%E8%A7%A3%E6%9E%90%E5%87%BD%E6%95%B0-parse-%E7%9A%84%E4%BD%BF%E7%94%A8">URL 解析函数 parse 的使用</a>。</p>
<blockquote>
<p><strong>注意：</strong></p>
<p>该函数可以解析 URL 中的用户名和密码（如果存在），这是符合 RFC 3986 协议的解析功能的，但是 RFC 3986 也明确指出，任何场景下，明文保存用户信息存在被泄露风险，所以建议不要在 URL 中明文保存用户信息。</p>
</blockquote>
<p>参数：</p>
<ul>
<li>rawUrl: String - <a href="url_package_classes.html#class-url">URL</a> 字符串。</li>
</ul>
<p>返回值：</p>
<ul>
<li><a href="url_package_classes.html#class-url">URL</a> - 解析字符串得到的 <a href="url_package_classes.html#class-url">URL</a> 实例。</li>
</ul>
<p>异常：</p>
<ul>
<li><a href="url_package_exceptions.html#class-urlsyntaxexception">UrlSyntaxException</a> - 当 <a href="url_package_classes.html#class-url">URL</a> 字符串中包含非法字符时，抛出异常。</li>
<li>IllegalArgumentException - 当被编码的字符不符合 <code>UTF-8</code> 的字节序列规则时，抛出异常。</li>
</ul>
<h3 id="func-isabsoluteurl"><a class="header" href="#func-isabsoluteurl">func isAbsoluteURL()</a></h3>
<pre><code class="language-cangjie">public func isAbsoluteURL(): Bool
</code></pre>
<p>功能：判断 <a href="url_package_classes.html#class-url">URL</a> 是否为绝对 <a href="url_package_classes.html#class-url">URL</a>（scheme 存在时，<a href="url_package_classes.html#class-url">URL</a> 是绝对 <a href="url_package_classes.html#class-url">URL</a>）。</p>
<p>返回值：</p>
<ul>
<li>Bool - scheme 存在时返回 true，不存在时返回 false。</li>
</ul>
<h3 id="func-replaceoptionstring-optionstring-optionstring-optionstring-optionstring-optionstring-optionstring"><a class="header" href="#func-replaceoptionstring-optionstring-optionstring-optionstring-optionstring-optionstring-optionstring">func replace(Option&lt;String&gt;, Option&lt;String&gt;, Option&lt;String&gt;, Option&lt;String&gt;, Option&lt;String&gt;, Option&lt;String&gt;, Option&lt;String&gt;)</a></h3>
<pre><code class="language-cangjie">public func replace(scheme!: Option&lt;String&gt; = None, userInfo!: Option&lt;String&gt; = None,
 hostName!: Option&lt;String&gt; = None, port!: Option&lt;String&gt; = None, path!: Option&lt;String&gt; = None, 
 query!: Option&lt;String&gt; = None, fragment!: Option&lt;String&gt; = None): URL
</code></pre>
<p>功能：替换 <a href="url_package_classes.html#class-url">URL</a> 对象的各组件，并且返回一个新的 <a href="url_package_classes.html#class-url">URL</a> 对象。</p>
<p>替换时需要满足以下要求：</p>
<ul>
<li>方案 scheme 为空时，主机名必须为空。</li>
<li>主机名为空时，用户信息或端口号必须为空。</li>
<li>方案 scheme 不为空时，主机名和路径不能同时为空。</li>
<li>方案 scheme 不为空时，路径必须是绝对路径。</li>
<li>任意组件均为合法字符。</li>
</ul>
<p>参数：</p>
<ul>
<li>scheme!: Option&lt;String&gt; - 协议组件。</li>
<li>userInfo!: Option&lt;String&gt; - 用户信息。</li>
<li>hostName!: Option&lt;String&gt; - 主机名。</li>
<li>port!: Option&lt;String&gt; - 端口号。</li>
<li>path!: Option&lt;String&gt; - 资源路径。</li>
<li>query!: Option&lt;String&gt; - 查询组件。</li>
<li>fragment!: Option&lt;String&gt; - 锚点组件。</li>
</ul>
<p>返回值：</p>
<ul>
<li><a href="url_package_classes.html#class-url">URL</a> - 新的 <a href="url_package_classes.html#class-url">URL</a> 对象。</li>
</ul>
<p>异常：</p>
<ul>
<li><a href="url_package_exceptions.html#class-urlsyntaxexception">UrlSyntaxException</a> - 不满足替换要求时，抛出异常。</li>
</ul>
<h3 id="func-resolveurlurl"><a class="header" href="#func-resolveurlurl">func resolveURL(URL)</a></h3>
<pre><code class="language-cangjie">public func resolveURL(ref: URL): URL
</code></pre>
<p>功能：以当前 <a href="url_package_classes.html#class-url">URL</a> 实例为基础 <a href="url_package_classes.html#class-url">URL</a>，以传入的 <a href="url_package_classes.html#class-url">URL</a> 为参考 <a href="url_package_classes.html#class-url">URL</a>，根据 RFC 3986 协议生成一个新的 <a href="url_package_classes.html#class-url">URL</a> 实例。</p>
<p>例如：<a href="http://a/b/c/d;p?q">http://a/b/c/d;p?q</a> 为基础 <a href="url_package_classes.html#class-url">URL</a>，以下 = 左边为参考 <a href="url_package_classes.html#class-url">URL</a>，右边为生成的新 <a href="url_package_classes.html#class-url">URL</a>：</p>
<ul>
<li>&quot;g&quot;      =  &quot;<a href="http://a/b/c/g">http://a/b/c/g</a>&quot;</li>
<li>&quot;/g&quot;     =  &quot;<a href="http://a/g">http://a/g</a>&quot;</li>
<li>&quot;g?y&quot;    =  &quot;<a href="http://a/b/c/g?y">http://a/b/c/g?y</a>&quot;</li>
<li>&quot;g?y#s&quot;  =  &quot;<a href="http://a/b/c/g?y#s">http://a/b/c/g?y#s</a>&quot;</li>
<li>&quot;../&quot;    =  &quot;<a href="http://a/b/">http://a/b/</a>&quot;</li>
</ul>
<p>更多详细的 URL 生成规则，请参见 RFC 3968 协议。</p>
<p>参数：</p>
<ul>
<li>ref: <a href="url_package_classes.html#class-url">URL</a> - 参考 <a href="url_package_classes.html#class-url">URL</a> 对象。</li>
</ul>
<p>返回值：</p>
<ul>
<li><a href="url_package_classes.html#class-url">URL</a> - 新的 <a href="url_package_classes.html#class-url">URL</a> 实例。</li>
</ul>
<h3 id="func-tostring"><a class="header" href="#func-tostring">func toString()</a></h3>
<pre><code class="language-cangjie">public func toString(): String
</code></pre>
<p>功能：获取当前 <a href="url_package_classes.html#class-url">URL</a> 实例的字符串值。</p>
<p>会把 hostName 编码，其余部分取 rawXXX (此处泛指前缀是 raw 的 URL 属性)属性值，按照 URL 组件构成顺序进行拼接而获得该函数返回值。</p>
<p>返回值：</p>
<ul>
<li>String - 当前 <a href="url_package_classes.html#class-url">URL</a> 实例的字符串值。</li>
</ul>
<h2 id="class-userinfo"><a class="header" href="#class-userinfo">class UserInfo</a></h2>
<pre><code class="language-cangjie">public class UserInfo &lt;: ToString {
    public init()
    public init(userName: String)
    public init(userName: String, passWord: String)
    public init(userName: String, passWord: Option&lt;String&gt;)
}
</code></pre>
<p>功能：<a href="url_package_classes.html#class-userinfo">UserInfo</a> 表示 URL 中用户名和密码信息。</p>
<blockquote>
<p><strong>注意：</strong></p>
<p>RFC 3986 明确指出，任何场景下，明文保存用户信息存在被泄露风险，所以建议不要在 URL 中明文保存用户信息。</p>
</blockquote>
<p>父类型：</p>
<ul>
<li>ToString</li>
</ul>
<h3 id="init-1"><a class="header" href="#init-1">init()</a></h3>
<pre><code class="language-cangjie">public init()
</code></pre>
<p>功能：创建 <a href="url_package_classes.html#class-userinfo">UserInfo</a> 实例。</p>
<h3 id="initstring-1"><a class="header" href="#initstring-1">init(String)</a></h3>
<pre><code class="language-cangjie">public init(userName: String)
</code></pre>
<p>功能：根据用户名创建 <a href="url_package_classes.html#class-userinfo">UserInfo</a> 实例。</p>
<p>参数：</p>
<ul>
<li>userName: String - 用户名。</li>
</ul>
<h3 id="initstring-optionstring"><a class="header" href="#initstring-optionstring">init(String, Option&lt;String&gt;)</a></h3>
<pre><code class="language-cangjie">public init(userName: String, passWord: Option&lt;String&gt;)
</code></pre>
<p>功能：根据用户名和密码创建 <a href="url_package_classes.html#class-userinfo">UserInfo</a> 实例。
参数：</p>
<ul>
<li>userName: String - 用户名。</li>
<li>passWord: Option&lt;String&gt; - 密码，用 Option&lt;String&gt; 类型表示。</li>
</ul>
<h3 id="initstring-string"><a class="header" href="#initstring-string">init(String, String)</a></h3>
<pre><code class="language-cangjie">public init(userName: String, passWord: String)
</code></pre>
<p>功能：根据用户名和密码创建 <a href="url_package_classes.html#class-userinfo">UserInfo</a> 实例。
参数：</p>
<ul>
<li>userName: String - 用户名。</li>
<li>passWord: String - 密码。</li>
</ul>
<h3 id="func-password"><a class="header" href="#func-password">func password()</a></h3>
<pre><code class="language-cangjie">public func password(): Option&lt;String&gt;
</code></pre>
<p>功能：获取密码信息。</p>
<blockquote>
<p><strong>注意：</strong></p>
<p>RFC 3986 明确指出，任何场景下，明文保存用户信息存在被泄露风险，所以建议不要在 URL 中明文保存用户信息。</p>
</blockquote>
<p>返回值：</p>
<ul>
<li>Option&lt;String&gt; - 将密码以 Option&lt;String&gt; 形式返回。</li>
</ul>
<h3 id="func-tostring-1"><a class="header" href="#func-tostring-1">func toString()</a></h3>
<pre><code class="language-cangjie">public func toString(): String
</code></pre>
<p>功能：将当前 <a href="url_package_classes.html#class-userinfo">UserInfo</a> 实例转换为字符串。</p>
<p>返回值：</p>
<ul>
<li>String - 当前 <a href="url_package_classes.html#class-userinfo">UserInfo</a> 实例的字符串表示。</li>
</ul>
<h3 id="func-username"><a class="header" href="#func-username">func username()</a></h3>
<pre><code class="language-cangjie">public func username(): String
</code></pre>
<p>功能：获取用户名信息。</p>
<p>返回值：</p>
<ul>
<li>String - 字符串类型的用户名。</li>
</ul>

                    </main>

                    <nav class="nav-wrapper" aria-label="Page navigation">
                        <!-- Mobile navigation buttons -->
                            <a rel="prev" href="../../../encoding/url/url_package_overview.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
                                <i class="fa fa-angle-left"></i>
                            </a>

                            <a rel="next prefetch" href="../../../encoding/url/url_package_api/url_package_exceptions.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
                                <i class="fa fa-angle-right"></i>
                            </a>

                        <div style="clear: both"></div>
                    </nav>
                </div>
            </div>

            <nav class="nav-wide-wrapper" aria-label="Page navigation">
                    <a rel="prev" href="../../../encoding/url/url_package_overview.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
                        <i class="fa fa-angle-left"></i>
                    </a>

                    <a rel="next prefetch" href="../../../encoding/url/url_package_api/url_package_exceptions.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
                        <i class="fa fa-angle-right"></i>
                    </a>
            </nav>

        </div>




        <script>
            window.playground_copyable = true;
        </script>


        <script src="../../../elasticlunr.min.js"></script>
        <script src="../../../mark.min.js"></script>
        <script src="../../../searcher.js"></script>

        <script src="../../../clipboard.min.js"></script>
        <script src="../../../cangjie-highlight-export.js"></script><script src="../../../highlight.js"></script>
        <script src="../../../book.js"></script>

        <!-- Custom JS scripts -->
        
        <script src="../../../cangjie-highlight-export.js"></script><script src="../../../highlight.js"></script>
        <script src="../../../assets/elasticlunr.js"></script>
        <script src="../../../assets/fzf.umd.js"></script>
        <script src="../../../assets/sidebar.js"></script>


    </div>
    </body>
</html>
